<template>
    <view class="bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="width: 1500px; text-align: center; background: white;">
                <div class="tr">
                    <div class="td text-center bold">促销类型</div>
                    <div class="td text-center bold">促销条件1</div>
                    <div class="td text-center bold">促销结果1</div>
                    <div class="td text-center bold">促销条件2</div>
                    <div class="td text-center bold">促销结果2</div>
                    <div class="td text-center bold">促销条件3</div>
                    <div class="td text-center bold">促销结果3</div>
                    <div class="td text-center bold">促销条件4</div>
                    <div class="td text-center bold">促销结果4</div>
                    <div class="td text-center bold">促销条件5</div>
                    <div class="td text-center bold">促销结果5</div>
                    <div class="td text-center bold">开始时间</div>
                    <div class="td text-center bold">结束时间</div>
                    <div class="td text-center bold">状态</div>
                    <div class="td text-center bold">操作</div>
                </div>
                <div class="tr" v-for="(item, index) in tbGoodsPromotionList" :key="item.id">
                    <div class="td">{{item.typeText}}</div>
                    <div class="td">{{item.if1 | toEmptyStr}}</div>
                    <div class="td">{{item.tbStorePresent1 ? item.tbStorePresent1.name : item.result1 | toEmptyStr}}</div>
                    <div class="td">{{item.if2 | toEmptyStr}}</div>
                    <div class="td">{{item.tbStorePresent2 ? item.tbStorePresent2.name : item.result2 | toEmptyStr}}</div>
                    <div class="td">{{item.if3 | toEmptyStr}}</div>
                    <div class="td">{{item.tbStorePresent3 ? item.tbStorePresent3.name : item.result3 | toEmptyStr}}</div>
                    <div class="td">{{item.if4 | toEmptyStr}}</div>
                    <div class="td">{{item.tbStorePresent4 ? item.tbStorePresent4.name : item.result4 | toEmptyStr}}</div>
                    <div class="td">{{item.if5 | toEmptyStr}}</div>
                    <div class="td">{{item.tbStorePresent5 ? item.tbStorePresent5.name : item.result5 | toEmptyStr}}</div>

                    <div class="td">{{item.startTime}}</div>
                    <div class="td">{{item.endTime}}</div>
                    <div class="td">{{item.statusText}}</div>
                    <div class="td">
                        <div style="margin-top: 5px; text-decoration: underline;"
                             @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-store-manage/store-platform-store-promotion/store-platform-store-promotion-edit/index', {id: item.id, excludeSubCods: '01,02,03,04,11,12,13,14,21,23,24,31,33,34'}, item)">
                            编辑
                        </div>
                        <div style="margin-top: 10px; margin-bottom: 10px; text-decoration: underline;" @click="deletePromotionById(item, index)">
                            删除
                        </div>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbGoodsPromotionList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="padding-bottom: 60px;"></div>

        <div class="custom-bottom-button">
            <label @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-store-manage/store-platform-store-promotion/store-platform-store-promotion-add/index', {excludeSubCods: '01,02,03,04,11,12,13,14,21,23,24,31,33,34'})">
                添加促销活动
            </label>
        </div>
    </view>
</template>

<script>

    import {TbStorePromotionService} from "@/dev/services/tb-store-promotion.service";
    import {CommonUtil} from "@/dev/core/utils/common.util";

    export default {
        data() {
            return {
                tbGoodsPromotionList: []
            }
        },
        onReady() {
            const _self = this

        },
        onShow() {
            this.findTbStorePromotionList();
        },
        methods: {
            findTbStorePromotionList() {
                const _self = this;
                new TbStorePromotionService().findTableTbStorePromotionList({
                    storeId: _self.globalVariable.userInfo.tbStore.id,
                }).then(result => {
                    _self.tbGoodsPromotionList = [];
                    _self.$nextTick(() => {
                        _self.tbGoodsPromotionList = result.list;
                    });
                });
            },
            /**
             * 删除规格
             * @param item
             */
            deletePromotionById(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbStorePromotionService().batchDeleteTbStorePromotionByIds(item.id).then(result => {
                                _self.tbGoodsPromotionList.splice(index, 1);
                            });
                        }
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
